//
//  BPOrderTableViewCell.m
//  BabyPhotograph
//
//  Created by cesh on 2017/1/13.
//  Copyright © 2017年 cesh. All rights reserved.
//

#import "BPOrderTableViewCell.h"
#import "BPChoosePicViewController.h"
#import <UIImageView+WebCache.h>

@interface BPOrderTableViewCell ()

@property (weak, nonatomic) IBOutlet UILabel *orderStatusLabel;
@property (weak, nonatomic) IBOutlet UILabel *countDownLabel;
@property (weak, nonatomic) IBOutlet UILabel *orderSerialNo;
@property (weak, nonatomic) IBOutlet UIImageView *orderImg;

@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *detail;
@property (weak, nonatomic) IBOutlet UILabel *photographer;
@property (weak, nonatomic) IBOutlet UILabel *time;
@property (weak, nonatomic) IBOutlet UILabel *address;

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

@property (weak, nonatomic) IBOutlet UIButton *bottomBtn;
@property (weak, nonatomic) IBOutlet UIButton *goReviewBtn;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomBtnWidth;

@end

@implementation BPOrderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.countDownLabel.hidden = YES;
    self.goReviewBtn.hidden = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)clickBtmBtn:(UIButton *)button {
    NSString *orderID = self.data[@"id"];
    if ([self.delegate respondsToSelector:@selector(pushViewController:orderID:)]) {
        [self.delegate pushViewController:self.orderCellType orderID:orderID];
    }
}

- (IBAction)clickGoReviewBtn:(UIButton *)button {
    if ([self.delegate respondsToSelector:@selector(pushGoReviewControllerWithOrderID:)]) {
        NSString *orderID = self.data[@"id"];
        [self.delegate pushGoReviewControllerWithOrderID:orderID];
    }
}

- (void)setData:(NSDictionary *)data {
    _data = data;
    //设置订单状态
    self.orderCellType = [data[@"status"] integerValue];
    _orderStatusLabel.text = data[@"statusDesc"];
    _orderSerialNo.text = data[@"orderNo"];
    //设置套餐情况
    _priceLabel.text = [NSString stringWithFormat:@"¥ %@", data[@"packageInfo"][@"price"]];
    _name.text = data[@"packageInfo"][@"title"];
    _detail.text = data[@"packageInfo"][@"desc"];
    _photographer.text = data[@"photographer"][@"name"];
    _time.text = data[@"time_str"];
    _address.text = [NSString stringWithFormat:@"%@ %@", data[@"address"][@"local"], data[@"address"][@"local_ext"]];
    [_orderImg sd_setImageWithURL:[NSURL URLWithString:data[@"packageInfo"][@"imgs"][0]] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    
}

- (void)setOrderCellType:(OrderCellType)orderCellType {
    _orderCellType = orderCellType;
    switch (orderCellType) {
        //1.待支付
        case OrderCellTypeNotPay:
        {
            self.countDownLabel.hidden = NO;
            [self.bottomBtn setTitle:@"去支付" forState:UIControlStateNormal];
        }
            break;
        //2.已支付（还没拍 等摄影师拍）
        case OrderCellTypeWaitForPhotographer:
        {
            [self.bottomBtn setTitle:@"申请退款" forState:UIControlStateNormal];
        }
            break;
        //3.已支付 (拍了 等传片)
        case OrderCellTypeWaitForChoosePics:
        {
            [self.bottomBtn setTitle:@"等待传片" forState:UIControlStateNormal];
            self.bottomBtn.userInteractionEnabled = NO;
            [self.bottomBtn setBackgroundImage:[UIImage imageNamed:@"rec_grey_1"] forState:UIControlStateNormal];
            [self.bottomBtn setTitleColor:[UIColor colorWithRed:0xd8 / 255.0 green:0xd8 / 255.0 blue:0xd8 / 255.0 alpha:1.0] forState:UIControlStateNormal];
        }
            break;
        //4.已传片
        case OrderCellTypeGoChoosePics:
        {
            [self.bottomBtn setTitle:@"去选片" forState:UIControlStateNormal];
        }
            break;
        //5.已选片
        case OrderCellTypeHaveChosenPics:
        {
            [self.bottomBtn setTitle:@"查看选片" forState:UIControlStateNormal];
        }
            break;
        //6.已完成
        case OrderCellTypeComplete:
        {
            [self.bottomBtn setTitle:@"查看原片" forState:UIControlStateNormal];
            self.goReviewBtn.hidden = NO;
        }
            break;
        //7.已评价
        case OrderCellTypeSubmitComment:
        {
            [self.bottomBtn setTitle:@"查看原片" forState:UIControlStateNormal];
        }
            break;
            
        default:
            break;
    }
}

@end
